package com.example.exercise.xiaodemos;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

/**
 * 配置语言包环境变量TESSDATA_PREFIX
 */
public class OCRDemo {

    public static void main(String[] args) {
        //图片文件
        File imageFile = new File("C:\\Users\\Administrator\\Desktop\\新建文件夹\\IMG_20250620_132308.jpg");
        ITesseract instance = new Tesseract();
        //语言包所在目录
        instance.setDatapath("E:\\static-source\\tessdata-OCR");
        //识别英文字符
        instance.setLanguage("eng");
        try {
            String result = instance.doOCR(imageFile);
            System.out.println(result);
        } catch (TesseractException e) {
            e.printStackTrace();
        }
    }
}
